<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>新增用户</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="新增,用户">
	<meta http-equiv="description" content="This is my page">

	<style type="text/css">
	.roleDivClass
	{
		display:inline;
		float:left;
		width:120;
	}
	</style>

  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'系统管理'},{'name':'用户管理'},{'name':'新增用户'}]"/>
    			<jsp:param name="width" value="70%"/>
    		</jsp:include>
    		
    		<table width="100%" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
    			<tr bgcolor="#FFFFFF">
    				<td width="15%" align="right" class="label">
    					用户帐号：
    					<br>
    					<font color="red">(16字以内)</font>
    				</td>
    				<td width="35%" align="left">
    					<s:textfield name="user.id" id="userId" cssStyle="width:80%" maxlength="16"></s:textfield>
    				</td>
    				<td width="15%" align="right" class="label">
    					用户名称：
    					<br>
    					<font color="red">(20字以内)</font>
    				</td>
    				<td width="35%" align="left">
    					<s:textfield name="user.username" id="username" cssStyle="width:80%" maxlength="20"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					密码：
    					<br>
    					<font color="red">(16字以内)</font>
    				</td>
    				<td align="left">
    					<s:password name="user.password" id="password" cssStyle="width:80%" maxlength="16"></s:password>
    				</td>
    				<td align="right" class="label">
    					确认密码：
    					<br>
    					<font color="red">(16字以内)</font>
    				</td>
    				<td align="left">
    					<s:password id="ensurePassword" cssStyle="width:80%" maxlength="16"></s:password>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					性别：
    				</td>
    				<td align="left">
    					<s:select list='#{"男":"男", "女":"女"}' cssStyle="width:120" name="user.sex" id="sex"></s:select>
    				</td>
    				<td align="right" class="label">
    					所属部门：
    				</td>
    				<td align="left">
    					<s:select list="deptList" listKey="id" listValue="deptName" headerKey="" headerValue="--请选择--" cssStyle="width:120" name="user.dept.id" id="deptId"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					使用情况：
    				</td>
    				<td align="left" colspan="3">
    					<s:radio list='#{"use":"已审核", "lock":"已锁定"}' name="user.useType" id="useType" value="'use'"></s:radio>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					分配角色：
    					<br>
    					全选<input type="checkbox" onclick="cbCheck(this, 'roleIds')" />
    				</td>
    				<td align="left" colspan="3">
    					<s:iterator value="roleList" status="s">
    						<div id="roleDiv<s:property value='id' />" class="roleDivClass">
    							<input type="checkbox" name="roleIds" id="role<s:property value='id' />" value="<s:property value='id' />" />
    							<s:property value="roleName"/>
    						</div>
    					</s:iterator>
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="新增" class="btn" onclick="addUser()" />
    				</td>
    			</tr>
    		</table>
    		
    		
    	</s:form>
    </center>
    
    <script type="text/javascript">
    function addUser()
    {
    	var userId = $('#userId');
    	var username = $('#username');
    	var password = $('#password');
    	var ensurePassword = $('#ensurePassword');
    	var deptId = $('#deptId');
    	if('' == userId.val().Trim())
    	{
    		showMsg('用户帐号不能为空。', function(){userId.focus();});
    		return;
    	}
    	if('' == username.val().Trim())
    	{
    		showMsg('用户名称不能为空。', function(){username.focus();});
    		return;
    	}
    	if('' == password.val().Trim())
    	{
    		showMsg('密码不能为空。', function(){password.focus();});
    		return;
    	}
    	if('' == ensurePassword.val().Trim())
    	{
    		showMsg('确认密码不能为空。', function(){ensurePassword.focus();});
    		return;
    	}
    	if(password.val().Trim() != ensurePassword.val().Trim())
    	{
    		showMsg('密码与确认密码必须相同。', function(){ensurePassword.focus();});
    		return;
    	}
    	if('' == deptId.val().Trim())
    	{
    		showMsg('部门不能为空。', function(){deptId.focus();});
    		return;
    	}
    	$.ajax({
    		url:'${CONTEXT_PATH}/inner/user/addUser.action',
    		type:'post',
    		data:$("#frm").serialize(),
    		dataType:'json',
    		success:
    			function(result){
    				if(result == true)
    				{
	    				showMsg('新增成功。', function(){
				    		window.close();
				    		window.opener.searchThis();
				    	});
				    }
				    else
				    {
				    	showMsg('已存在该用户，请重新输入帐号。');
				    }
    			}
    	});
    }
    </script>
  </body>
</html>
